define(function(require){
	var main =require('/modules/js/seajs/main.js');
	var m = new main();
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		_init:function(){
			this.addinfo();
			this.eidtUser();
			this.delUser();
		},
		addinfo:function(){
			// type 100 添加  200 编辑
			var btn = m.QS('#commentForm');
			m.addEvent(btn,'submit',function(e){
				var v  = e.target.dataset,$levelNo = '';
				var type  = v.type;
				var userid  = v.userid;
				var ENTCodeobj = m.QS('#ENTCode');
				var UserLevelNoobj = m.QS('#UserLevelNo');
				var codeIndex = ENTCodeobj.selectedIndex;
				var ENTCode = ENTCodeobj.options[codeIndex].value;
				var leveIndex = UserLevelNoobj.selectedIndex;
				var UserLevelNo = UserLevelNoobj.options[leveIndex].value;
				var data = {
					'Nickname': m.QS('#Nickname').value,
					'Phone': m.QS('#Phone').value,
					'ENTCode': ENTCode,
					'UserLevelNo': UserLevelNo,
					'type':type,
					'UserId':userid,
				}
				switch (UserLevelNo) {
    				case '1':
    					$levelNo = '初出茅庐';
    					break;
    				case '2':
    					$levelNo = '销售达人';
    					break;
    				case '3':
    					$levelNo = '金牌销售';
    					break;
    				case '4':
    					$levelNo = '超级管理';
    					break;
    				case '99':
    					$levelNo = '平台';
    					break;
    			}
				m.post({
					url:'/employee/create-user-info',
					data:data,
					success:function (ret) {
		                if (ret.IsBizSuccess) {
		                	var msg = parseInt(type)  == 100 ? '添加成功':'修改成功';
		                	layer.msg(msg);
		     //            	var str = '<button class="btn btn-info btn-xs eidtUser" type="button" style="margin-bottom: 0px;" data-toggle="modal" data-target="#AddRole" data-name="'+data.Nickname+'" data-code="'+data.ENTCode+'" data-leveno="'+data.UserLevelNo+'" data-cellphone="'+data.Phone+'" data-userid="'+ret.UserId+'" ><i class="fa fa-pencil-square-o"></i> 编辑</button>\
						 //   <button class="btn btn-danger btn-xs delUser" type="button" style="margin-bottom: 0px;" data-userid="'+ret.UserId+'" ><i class="fa fa-times"></i> 删除</button>'
							// $("#editable").dataTable().fnAddData([1,data.Nickname,data.ENTCode,$levelNo,data.Phone,str]);
							// $('#userSaveBtn').click();
							$("#editable").dataTable().ajax.reload();
		                } else {
							layer.msg(ret.ErrMsg);
							return ;
		                }
		            }
            	})
            	var e = e || window.event;  
    			if (e.preventDefault) e.preventDefault();  
    			else window.event.returnValue = false; 
			})
			// 点击添加
			$(document).on('click','.AddRole',function(e){
				m.QS('#commentForm').setAttribute('data-type',100)
				m.QS('.ENTCode').style.display = 'block';
				m.QS('#Nickname').value = '';
				m.QS('#Phone').value = '';
				m.QS('#ENTCode').value = '';
				m.QS('#UserLevelNo').value = '';
			})
		},
		eidtUser:function(){
			$(document).on('click','.eidtUser',function(e){
				var v = e.target.dataset;
				m.QS('.ENTCode').style.display = 'none';
				m.QS('#commentForm').setAttribute('data-type',200)
				m.QS('#commentForm').setAttribute('data-userid',v.userid)
				var data = {
					'Nickname':v.name,
					'Phone': v.cellphone,
					'ENTCode': v.code,
					'UserLevelNo': v.leveno,
				}
				m.QS('#Nickname').value = data.Nickname;
				m.QS('#Phone').value = data.Phone;
				m.QS('#ENTCode').value = data.ENTCode;
				m.QS('#UserLevelNo').value = data.UserLevelNo;
			});
		},
		
	}
	var a = new Cont();


})